import api from '@api'

const state = {
  data: {
    bargainList: [],
    userInfo: {},
    goodsInfo: {},
    isload: false
  }

}

const getters = {
  ['getData'] (state) {
    return state.data
  }
}

const actions = {
  async ['getData'] ({commit, state}) {
    let {data: {StatusCode, bargainList, userInfo, goodsInfo}} = await api.get('api/v2/Bargain/userBargainInfo.ashx', {goSn: 'LM001'});
    if(StatusCode == 200) {
      commit('setData', {bargainList, userInfo: userInfo[0], goodsInfo: goodsInfo[0]});
    }
    return StatusCode;
  },
  async ['getBargainData'] ({commit, state},bargain) {
    let {data: {StatusCode, bargainList, userInfo, goodsInfo}} = await api.get('api/v2/Bargain/BargainOtherInfo.ashx', {goSn: 'LM001', bargain});
    if(StatusCode == 200) {
      commit('setData', {bargainList, userInfo: userInfo[0], goodsInfo: goodsInfo[0]});
    }

  }
}

const mutations = {
  ['setData'] (state, {bargainList, userInfo, goodsInfo}) {
    state.data.bargainList = bargainList;
    state.data.userInfo = userInfo;
    state.data.goodsInfo = goodsInfo;
    state.data.isload = true;
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}

